/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean.custom;

import com.jb.web.context.WebContext;

import java.util.ArrayList;
import java.util.List;

import javax.swing.ListModel;
import javax.swing.event.ListDataListener;


public class FileListModel implements ListModel {
    protected List list = new ArrayList();
    protected transient boolean dirty = true;
    private String fileLocation;

    public FileListModel() {
    }

    public Object getElementAt(int index) {
        return list.get(index);
    }

    public void setFileLocation(String loc) {
        loc = loc.replace('\\', '/');

        if (loc.equals(fileLocation)) {
            return;
        }

        this.fileLocation = loc;
        this.dirty = true;
    }

    public String getFileLocation() {
        return fileLocation;
    }

    public List getList(WebContext pCtx) {
        load(pCtx);
        dirty = true;

        return list;
    }

    public List getList() {
        return list;
    }

    public int getSize() {
        return list.size();
    }

    public void addListDataListener(ListDataListener l) {
    }

    public void remove(WebContext pCtx, Object obj) {
        FileNode fn = (FileNode) obj;
        fn.delete(pCtx);
        list.remove(obj);
    }

    public void removeListDataListener(ListDataListener l) {
    }

    protected void load(WebContext pCtx) {
        //
    }
}
